<html>
<head>
<title>
websocket 聊天
</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>

<body>
<center>

<div>
<div>
<textarea id="chat" style="width:216px;height:300px;scroll-behavior: auto"></textarea>

</div>  
<div>
<input id="msg" type="text"  width="100px;"/><input type="button" value="发送"  onclick="send()"/> 
</div>   
</div>


</center>

<script>
 var ws = new WebSocket("ws://106.13.63.203:8082");
  
 ws.onopen = function()
{  console.log("open");

  ws.send("hello");

};

ws.onmessage = function(evt)

{

 $("#chat").append(evt.data);
 $("#chat").append("\n");
  console.log(evt.data);

};

ws.onclose = function(evt)

{

  console.log("WebSocketClosed!");

};

ws.onerror = function(evt)

{

  console.log("WebSocketError!");

};


function send()
{
   var text = $("#msg").val();   
    ws.send(text);
    $("#msg").val("");
}

</script>    
</body>
</html>